﻿--[[
   @brief    
   @author   rickonzhang
   @version  1.0
   @date     2015-08-25
--]]

contact_menu_control = 
{
    reddot_id_list_ = {};
};

function contact_menu_control.on_get_friend_list_done(event_id, json_str)
    -- im 初始化成功后打开按钮
    contact_menu_control.is_get_friend_list_done_ = true;
    contact_menu_control.enbale_search_and_create();
end

function contact_menu_control.on_get_group_list_done(event_id, json_str)
    -- im 初始化成功后打开按钮
    contact_menu_control.is_get_group_list_done_ = true;
    contact_menu_control.enbale_search_and_create();
end

function contact_menu_control.is_wegamehk()
    return base_utility.is_type_of_oversea_ver();
end

function contact_menu_control.enbale_search_and_create()
    if contact_menu_control.is_get_friend_list_done_ == true and
        contact_menu_control.is_get_group_list_done_ == true then
        if contact_menu_control.search_btn_id1_ ~= nil then
            ui_utility.setproperty_by_id(contact_menu_control.search_btn_id1_, "Disable", "false");
        end
        if contact_menu_control.search_btn_id2_ ~= nil then
            ui_utility.setproperty_by_id(contact_menu_control.search_btn_id2_, "Disable", "false");
        end
        if contact_menu_control.create_discuss_btn_id1_ ~= nil then
            ui_utility.setproperty_by_id(contact_menu_control.create_discuss_btn_id1_, "Disable", "false");
        end
        if contact_menu_control.create_discuss_btn_id2_ ~= nil then
            ui_utility.setproperty_by_id(contact_menu_control.create_discuss_btn_id2_, "Disable", "false");
        end
    end
end

function contact_menu_control.on_search_btn_create(uilib, ctrl_id)
    if contact_menu_control.search_btn_id1_ == nil then
        contact_menu_control.search_btn_id1_ = ctrl_id;
    else
        contact_menu_control.search_btn_id2_ = ctrl_id;
    end

    if contact_menu_control.is_get_friend_list_done_ == true and
        contact_menu_control.is_get_group_list_done_ == true then
        ui_utility.setproperty_by_id(ctrl_id, "Disable", "false");
    end
end

function contact_menu_control.on_create_discuss_btn_create(uilib, ctrl_id)
    if contact_menu_control.create_discuss_btn_id1_ == nil then
        contact_menu_control.create_discuss_btn_id1_ = ctrl_id;
    else
        contact_menu_control.create_discuss_btn_id2_ = ctrl_id;
    end

    if contact_menu_control.is_get_friend_list_done_ == true and
        contact_menu_control.is_get_group_list_done_ == true then
        ui_utility.setproperty_by_id(ctrl_id, "Disable", "false");
    end
end

function contact_menu_control.on_click_create_discuss_btn(uilib, ctrl_id)
    if login_model.im_login_infomation ~= nil and login_model.social_user_level > 0 then

        local btn = ui_utility.get_ctrl_ptr_by_id(ctrl_id);
        local rc = btn:GetRectEx(TRUE,TRUE);
        local param = {x = rc.left, y = rc.top};
        event_center.send_event(social_event.SHOW_CREATE_GROUP_MENU, base_utility.table_to_json(param));

        comm_center.call_service('i_service_tqos_socail_click_create_discussion_btn', {});
    end
end

function contact_menu_control.on_click_social_menu(uilib, ctrl_id)
    if login_model.im_login_infomation ~= nil and login_model.social_user_level > 0 then
        comm_center.call_service('i_service_tqos_friend_search_menu_click', {});

        local btn = ui_utility.get_ctrl_ptr_by_id(ctrl_id);
        local rc = btn:GetRectEx(TRUE,TRUE);
        local param = {x = rc.left, y = rc.top};
        event_center.send_event(group_event.SHOW_FRIEND_SEARCH_MENU,base_utility.table_to_json(param));     

        comm_center.call_service('i_service_increase_social_panel_bottom_menu_click_cnt', {});
    end
end

function contact_menu_control.show_reddot(data)
    if data ~= nil and data.is_show ~= nil  then
        contact_menu_control.is_show_reddot = data.is_show;
        contact_menu_control.update_reddot_ui()
    end
end

function contact_menu_control.on_reddot_create(uilib, ctrl_id)
    table.insert(contact_menu_control.reddot_id_list_, ctrl_id);
    contact_menu_control.update_reddot_ui();
end

function contact_menu_control.update_reddot_ui()
    local is_show = "false";
    if contact_menu_control.is_show_reddot == "true" then
        is_show = "true";
    end
    
    for k, v  in pairs(contact_menu_control.reddot_id_list_) do
        ui_utility.setproperty_by_id(v, "Visible", is_show);
    end

end

